<?php
defined('_JEXEC') or die;

jimport('joomla.application.component.modelform');
 
class EventosModelEventos extends JModel {
	
  public function datos_grid(){
	 	
 	$db = &JFactory::getDBO();
    $pagination = false;
	if (isset($_REQUEST["page"])) {
	   $pagination = true;	
	   $page = intval($_REQUEST["page"]);
	   
	}else{
		$page=0;
	}

	if(isset($_REQUEST["perpage"]))
		$perpage = intval($_REQUEST["perpage"]);
	else
		$perpage = 10;
		
		
	// this variables Omnigrid will send only if serverSort option is true
    if(isset($_REQUEST["sorton"])) { $sorton = $_REQUEST["sorton"]; }else{ $sorton = null; }
	if(isset($_REQUEST["sortby"])) { $sortby = $_REQUEST["sortby"]; }else{ $sortby = null; }
	
	$n = ( $page -1 ) * $perpage;
        $limit = "";
	
	if ( $pagination )
		$limit = "LIMIT $n, $perpage";
	
	$sql= "SELECT CONCAT('<input type=checkbox value=',iddeporte,' name=checks ></input>') as sele" .
			",deporte " .
			",tip.tipo".
			",minimo".
			",maximo".
			",CASE WHEN dep.idestado=1 then 'ACTIVO' ELSE 'INACTIVO' END as estado".
			",CONCAT('<a href=javascript:void(0); onclick=editar_deportes(',iddeporte,') >Editar</a>') as editar " .
			" FROM #__deportes dep join #__tipos tip using (idtipo) ";
			
	if($sorton) $sql.=" ORDER BY $sorton $sortby ";
	
	if($limit) $sql.=" $limit ";
	
	
        $db->setQuery($sql);
        $db->query();
        $total = $db->getNumRows();
        $row = $db->loadObjectList();
	
	$row = array("page"=>$page, "total"=>$total, "data"=>$row);

	echo json_encode($row);
 }
 	
}
